//
// Created by 11510 on 2024/6/17.
//

#ifndef DEMO1_EMPLOYEE_H
#define DEMO1_EMPLOYEE_H

#include <vector>
using std::vector;
#include "Person.h"

class Employee: public Person{
private:
    int salary;
    char* department;
    static int sumSalaries;
    static int numberOfPeople;


public:
    int getSalary() const {
        return salary;
    }

    /* 有参构造 */
    Employee(const char* name, int age, int salary, const char* department):
    Person(name,age), salary(salary), department( new char[strlen(department) + 1]()){
        strcpy(this->department, department);

        sumSalaries += salary;
        numberOfPeople++;
    }

    /* 拷贝构造 */
    Employee(const Employee& rhs):
    Person(rhs),salary(rhs.salary), department( new char[strlen(rhs.department) + 1]()){
        strcpy(this->department, rhs.department);

        sumSalaries += rhs.salary;
        numberOfPeople++;
    }

    /* 析构 */
    ~Employee(){
//        printf("~Employee()\n");
        if(department != nullptr){
            delete[] department;
            department = nullptr;
        }
    }

    /* 赋值 */
    Employee& operator=(const Employee& rhs){
        if(&rhs != this){
            Person::operator=(rhs);

            delete[] department;
            department = new char[strlen(rhs.department) + 1]();
            strcpy(this->department, rhs.department);

            sumSalaries -= salary;
            sumSalaries += rhs.salary;

            salary = rhs.salary;
        }
        return *this;
    }

    void display()const{
        Person::display();
        printf("department = %s, salary = %d\n", department, salary);
    }

    static double agvSalary();

};


#endif //DEMO1_EMPLOYEE_H
